package com.example.admin.controller;


import com.example.admin.common.Result;
import com.example.admin.entity.ElderChildrenInfo;
import com.example.admin.service.ElderChildrenService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
@CrossOrigin(origins = "http://localhost:8080")
public class ElderChildrenController {

    @Autowired
    private ElderChildrenService elderChildrenService;

    @GetMapping("/getElderChildrenPage")
    public Result<PageInfo> getElderChildrenPage(@RequestParam Integer pageNumber,@RequestParam Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
       List<ElderChildrenInfo> elderChildrenInfos= elderChildrenService.getElderChildrenPage();
       return Result.success(new PageInfo(elderChildrenInfos));
    }


    @DeleteMapping("/deleteElderChirdenById/{id}")
    public Result deleteElderChirdenById(@PathVariable Integer id) {
      Result result=  elderChildrenService.deleteElderChirdenById(id);
      return result;

    }

    @PostMapping("/addElderChirden")
    public Result addElderChirden(@RequestBody ElderChildrenInfo elderChildrenInfo) {

       Result result= elderChildrenService.addElderChirden(elderChildrenInfo);
       return result;
    }


    @PutMapping("/editeElderChildren")
    public Result editeElderChildren(@RequestBody ElderChildrenInfo elderChildrenInfo) {
        Result result=elderChildrenService.editeElderChildren(elderChildrenInfo);
        return result;
    }

    @GetMapping("/selectElderChilrdrenByElderID")
    public Result<PageInfo> selectElderChilrdrenByName(@RequestParam Integer elderId) {
        PageHelper.startPage(1,10);
       List<ElderChildrenInfo> elderChildrenInfoList= elderChildrenService.selectElderChilrdrenByName(elderId);
       return Result.success(new PageInfo(elderChildrenInfoList));
    }






}
